from scrapy import signals

class SpiderMonitorExtension:
    def __init__(self, crawler):
        self.crawler = crawler
        crawler.signals.connect(self.spider_opened, signal=signals.spider_opened)
        crawler.signals.connect(self.spider_closed, signal=signals.spider_closed)

    def spider_opened(self, spider):
        spider.logger.info(f"================ Spider opened: {spider.name} ================")

    def spider_closed(self, spider):
        spider.logger.info(f"================Spider closed: {spider.name} ================")

    @classmethod
    def from_crawler(cls, crawler):
        return cls(crawler)